//package utils;
//
//import org.apache.thrift.TFieldIdEnum;
//import org.apache.thrift.meta_data.FieldMetaData;
//import org.apache.thrift.meta_data.FieldValueMetaData;
//import org.apache.thrift.protocol.TBinaryProtocol;
//import org.apache.thrift.protocol.TProtocol;
//import org.apache.thrift.protocol.TType;
//import org.apache.thrift.transport.TFramedTransport;
//import org.apache.thrift.transport.TSocket;
//import org.apache.thrift.transport.TTransport;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.BeanInitializationException;
//import org.springframework.util.ReflectionUtils;
//
//import java.lang.reflect.Field;
//import java.lang.reflect.Method;
//import java.util.HashMap;
//import java.util.Map;
//
///**
// * @description: 发起thrift调用
// * @author: zhouliangliang03
// * @create: 2020-07-20 15:41
// **/
//public class ThriftCallUtil {
//
//    private static final Logger logger = LoggerFactory.getLogger(ThriftCallUtil.class);
//
//    private static final Class POIThriftServerClass = null;
//
//    private static final HashMap<String, Method> ThriftServerMethodMapping = new HashMap<>();
//
//    static {
//        for (Method method : POIThriftServerClass.getMethods()) {
//            String methodName = method.getName();
//            System.out.println(methodName);
//            try {
//                ThriftServerMethodMapping.put(methodName, method);
////                Document methodDocument = getMethodIdl(methodName);
////                FacadeThriftServerDocumentMapping.put(methodName, methodDocument);
//                logger.warn("Parse POIThriftServerClass.{} to idl success!", methodName);
//            } catch (Exception e) {
//                logger.warn("Parse POIThriftServerClass.{} to idl failed!", methodName, e);
//                throw new BeanInitializationException("Init ", e);
//            }
//        }
//    }
//
//    public static Object callThriftMethod(String methodName, String ipPort, Map<String, Object> paramsMap) throws Exception{
//        String[] ipt = ipPort.split(":");
//        String ip = ipt[0];
//        int port = Integer.parseInt(ipt[1]);
//        try {
//            //完成接口配置
//            TTransport transport = new TFramedTransport(new TSocket(ip, port,3000));
//            transport.open();
//            TProtocol protocol = new TBinaryProtocol(transport);
//        //    PoiService.Client client = new PoiService.Client(protocol);
//
//            //获得client需要调用的method
//            Method method = ThriftServerMethodMapping.get(methodName);
//            Class[] paramsType = method.getParameterTypes();
//
//            //入参的request的类型
//            Class requestClass = paramsType[0];
//            //获取一个入参的对象
//            Object requestObject = requestClass.newInstance();
//
//            //从request当中查找metaDataMap
//            Field metaDataMapField = ReflectionUtils.findField(requestClass, "metaDataMap");
//
//            //从request中获取metaDataMap对象
//            Map<TFieldIdEnum, FieldMetaData> metaDataMap = (Map<TFieldIdEnum, FieldMetaData>) ReflectionUtils.getField(metaDataMapField, "metaDataMap");
//
//
//            //获取内部类_Fields
//            Class _FieldClass = Class.forName(requestClass.getName() + "$_Fields");
//
//            //获取_Fields的set方法
//            Method setMethod = ReflectionUtils.findMethod(requestClass, "setFieldValue", _FieldClass, Object.class);
//
//            //生成request对象
//            for (Map.Entry<TFieldIdEnum, FieldMetaData> tFieldIdEnumFieldMetaDataEntry : metaDataMap.entrySet()) {
//                //_Fields的属性
//                TFieldIdEnum idEnum = tFieldIdEnumFieldMetaDataEntry.getKey();
//
//                //属性的元类型
//                FieldMetaData metaData = tFieldIdEnumFieldMetaDataEntry.getValue();
//
//                //数组当中获取元类型的名称(例如:requestUri)不为空
//                if (paramsMap.get(metaData.fieldName) != null) {
//                    //获取元类型的值
//                    Object value = paramsMap.get(metaData.fieldName);
//                    //获取元类型的类型
//                    FieldValueMetaData valueMetaData = metaData.valueMetaData;
//                    switch (valueMetaData.type) {
//                        case TType.BOOL:
//                            setMethod.invoke(requestObject, idEnum, Boolean.valueOf(value.toString()));
//                            break;
//                        case TType.BYTE:
//                            setMethod.invoke(requestObject, idEnum, Byte.valueOf(value.toString()));
//                            break;
//                        case TType.DOUBLE:
//                            setMethod.invoke(requestObject, idEnum, Double.valueOf(value.toString()));
//                            break;
//                        case TType.I16:
//                            setMethod.invoke(requestObject, idEnum, Short.valueOf(value.toString()));
//                            break;
//                        case TType.I32:
//                            setMethod.invoke(requestObject, idEnum, Integer.valueOf(value.toString()));
//                            break;
//                        case TType.I64:
//                            setMethod.invoke(requestObject, idEnum, Long.valueOf(value.toString()));
//                            break;
//                        case TType.STRING:
//                            setMethod.invoke(requestObject, idEnum, value);
//                            break;
//                        case TType.MAP:
//                            setMethod.invoke(requestObject, idEnum, value);
//                    }
//                }
//            }
//             return method.invoke(client, requestObject);
//        } catch (Exception e) {
//            throw e;
//        }
//    }
//}

//public void test() throws Exception {
//        TTransport transport = new TFramedTransport(new TSocket("127.0.0.1", 8416,1000));
//        transport.open();
//        TProtocol protocol = new TBinaryProtocol(transport);
//        PoiService.Client client = new PoiService.Client(protocol);
//
//        }
